package org.vison.framework.doc;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.vison.framework.doc.config.DocProperties;
import org.vison.framework.doc.DocScanner;

/**
 * wonfu-doc模块自动配置类
 * 负责自动注册文档模块的组件到Spring容器
 * 只有当wonfu.doc.enable=true时才启用整个文档功能
 */
@Configuration
@EnableConfigurationProperties(DocProperties.class)
@ComponentScan(basePackages = "org.vison.framework.doc")
@ConditionalOnProperty(prefix = "wonfu.doc", name = "enabled", havingValue = "true", matchIfMissing = true)
public class DocAutoConfiguration {
    
    /**
     * 注册REST接口文档扫描器
     * 当启用文档功能时，默认同时开启REST接口文档
     * 
     * @return RestDocScanner实例
     */
    @Bean
    @ConditionalOnMissingBean
    public DocScanner restDocScanner() {
        return new DocScanner();
    }
    
    /**
     * 注册SOA接口文档扫描器
     * 当启用文档功能时，默认同时开启SOA接口文档
     * 
     * @return SoaDocScanner实例
     */
    @Bean
    @ConditionalOnMissingBean
    public DocScanner soaDocScanner() {
        return new DocScanner();
    }
}